package com.zqw.util;

import com.zqw.pojo.AuthPojo;
import com.zqw.pojo.RolePojo;
import org.apache.log4j.Logger;

import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

public class StringUtil {

    static Logger log = Logger.getLogger(StringUtil.class);

    //对字符串进行非空校验
    public static boolean isEmpty(String str){
        if(str == null||"".equals(str)){
            return true;
        }return false;
    }

    //判断是否有访问该网址的权限
    public static boolean pageContains(List<RolePojo> list,String target){

        Iterator<RolePojo> iterator = list.iterator();
        while (iterator.hasNext()){
            RolePojo next = iterator.next();
            Iterator<AuthPojo> iterator1 = next.getAuths().iterator();
            while (iterator1.hasNext()){
                AuthPojo next1 = iterator1.next();
                if(next1.getAupath().contains(target)){
                    return true;
                }
            }
        }
        return false;
    }

    //从a中找b中不存在的
    public static String[] findNo(String[] a,String[] b){
        Set<String> str = new HashSet<String>();
        boolean stat;
        for (int i = 0; i < a.length; i++) {
            stat = true;
            for (int j = 0; j < b.length; j++) {
                if(a.equals(b)){
                    stat = false;
                    break;
                }
            }
            if(stat){
                str.add(a[i]);
            }
        }
        return str.toArray(new String[str.size()]);
    }

    public static void info(String str){
        log.info(str);
    }

    public static void debug(String str){
        log.debug(str);
    }

}
